package components
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.containers.TabNavigator;
	import mx.controls.Button;
	import mx.controls.DataGrid;
	import mx.core.Container;
	import mx.events.ListEvent;
	import mx.events.ResizeEvent;
	
	import nl.wv.extenders.panel.SuperPanel;
	
	import tools.*;
	
	public class Messages{
		private var tool:Tool = new Tool();
		private var panel:SuperPanel = new SuperPanel();
		private var tabNavigator:TabNavigator = new TabNavigator();
		private var primljene:Container = new Container();
		private var poslate:Container = new Container();
		private var uToku:Container = new Container();
		private var arhiva:Container = new Container();
		private var service:Mysql = new Mysql();
		private var service1:Mysql = new Mysql();
		private var listaPrimljene:DataGrid = new DataGrid();
		private var listaPoslate:DataGrid = new DataGrid();
		private var listaUToku:DataGrid = new DataGrid();
		private var listaArhiva:DataGrid = new DataGrid();
		private var izbrisi:Button = new Button();
		private var arhiviraj:Button = new Button();
		private var nova:Button = new Button();
		private var checkAll:Button = new Button();
		private var unCheckAll:Button = new Button();
		
		public function Messages(p:SuperPanel){
			panel = p;
			tabNavigator.x = 10;
			tabNavigator.y = 27;
			tabNavigator.width = panel.width-35;
			tabNavigator.height = panel.height-85;
			
			izbrisi.label = "Izbrisi";
			izbrisi.x = panel.width-88;
			izbrisi.y = panel.height-45;
			arhiviraj.label = "Arhiviraj";
			arhiviraj.x = panel.width-168;
			arhiviraj.y = panel.height-45;
			nova.label = "Nova";
			nova.x = panel.width-236;
			nova.y = panel.height-45;
			checkAll.label = "O";
			checkAll.width = 32;
			checkAll.x = 10;
			checkAll.y = panel.height-45;
			checkAll.toolTip = "Oznaci sve";
			unCheckAll.label = "S";
			unCheckAll.x = 47;
			unCheckAll.y = panel.height-45;
			unCheckAll.width = 32;
			unCheckAll.toolTip = "Skini oznake";
			
			primljene.label = "Primljene";
			poslate.label = "Poslate";
			uToku.label = "U toku";
			arhiva.label = "Arhiva";
			
			tabNavigator.addChild(primljene);
			tabNavigator.addChild(poslate);
			tabNavigator.addChild(uToku);
			tabNavigator.addChild(arhiva);
			
			panel.addChild(tabNavigator);
			panel.addChild(izbrisi);
			panel.addChild(arhiviraj);
			panel.addChild(nova);
			panel.addChild(checkAll);
			panel.addChild(unCheckAll);
						
			listaArhiva.x = 0;
			listaArhiva.y = 0;
			listaArhiva.width = tabNavigator.width-2;
			listaArhiva.height = tabNavigator.height-32;
			listaPrimljene.x = 0;
			listaPrimljene.y = 0;
			listaPrimljene.width = tabNavigator.width-2;
			listaPrimljene.height = tabNavigator.height-32;
			listaPoslate.x = 0;
			listaPoslate.y = 0;
			listaPoslate.width = tabNavigator.width-2;
			listaPoslate.height = tabNavigator.height-32;
			listaUToku.x = 0;
			listaUToku.y = 0;
			listaUToku.width = tabNavigator.width-2;
			listaUToku.height = tabNavigator.height-32;
			listaPoslate.allowMultipleSelection = true;
			listaPrimljene.allowMultipleSelection = true;
			listaUToku.allowMultipleSelection = true;
			listaArhiva.allowMultipleSelection = true;
			
			primljene.addChild(listaPrimljene);
			poslate.addChild(listaPoslate);
			uToku.addChild(listaUToku);
			arhiva.addChild(listaArhiva);

			changeContent("Primljene");
			
			tabNavigator.addEventListener(Event.CHANGE, onChange);
			panel.addEventListener(ResizeEvent.RESIZE, onResize);
			checkAll.addEventListener(MouseEvent.CLICK, onCheckAll);
			unCheckAll.addEventListener(MouseEvent.CLICK, onUnCheckAll);
			arhiviraj.addEventListener(MouseEvent.CLICK, onArhive);
			izbrisi.addEventListener(MouseEvent.CLICK, onDelete);
			nova.addEventListener(MouseEvent.CLICK, onNova);
			listaPrimljene.addEventListener(ListEvent.ITEM_DOUBLE_CLICK, viewMessage);
			listaPoslate.addEventListener(ListEvent.ITEM_DOUBLE_CLICK, viewMessage);
			listaArhiva.addEventListener(ListEvent.ITEM_DOUBLE_CLICK, viewMessage);
			listaUToku.addEventListener(ListEvent.ITEM_DOUBLE_CLICK, viewMessage);
		}
		
		public function viewMessage(e:ListEvent):void{
			if(!panel.parentApplication.checkExist(e.itemRenderer.data.@naslov)){
				var s:SuperPanel;
				panel.parentApplication.panels.push(s = tool.createPanel(e.itemRenderer.data.@naslov, 0, 400, 400, 150, 100, true, true, e.itemRenderer.data.@naslov));
				panel.parentApplication.addChild(s);
				s.backButton.addEventListener(MouseEvent.CLICK, panel.parentApplication.taskbarButtonClicked);
				s.backButton.addEventListener(MouseEvent.RIGHT_CLICK, panel.parentApplication.taskbarButtonRightClicked);
				var n:ViewMessage = new ViewMessage(s);
				if(e.itemRenderer.data.@posiljaoc!=panel.parentApplication.username) n.reply();
				if(e.itemRenderer.data.@procitana=="Ne"&&tabNavigator.selectedChild.label=="Primljene"){
					n.show(e.itemRenderer.data.@naslov, e.itemRenderer.data.@username, e.itemRenderer.data.@fullPoruka, e.itemRenderer.data.@datumSlanja, e.itemRenderer.data.@vrijemeslanja, tool.currentDate(), tool.currentTime());
					service1.sql = {type:"UPDATE", tables:"privatnaporuka p", s1:"p.procitana=1", s2:"p.datumPrimanja=@"+tool.currentDate()+"@", s3:"p.vrijemeprimanja=@"+tool.currentTime()+"@", where:"p.id_poruka="+e.itemRenderer.data.@id_poruka };
	 				service1.addEventListener(service1.MYSQL_RESULT, onMarkAsRead);
		 			service1.startService();
				} else {
					n.show(e.itemRenderer.data.@naslov, e.itemRenderer.data.@username, e.itemRenderer.data.@fullPoruka, e.itemRenderer.data.@datumSlanja, e.itemRenderer.data.@vrijemeslanja, e.itemRenderer.data.@datumPrimanja, e.itemRenderer.data.@vrijemeprimanja);
				}
			}
		}
		
		public function onMarkAsRead(e:Event):void{
			service.sql = {type:"SELECT", a1:"p.id_poruka", a2:"p.posiljaoc", a3:"k.username", a4:"p.procitana", a5:"p.poruka", a6:"p.attachments", a7:"p.datumSlanja", a8:"p.datumPrimanja", a9:"p.vrijemeslanja", a10:"p.vrijemeprimanja", a11:"p.naslov", a12:"p.primaoc", from:"privatnaporuka p, korisnik k", where:"k.id_username=p.posiljaoc AND procitana < 2 AND p.primaoc="+panel.parentApplication.username+" ORDER BY p.datumSlanja DESC, p.vrijemeslanja DESC" };
	 		service.addEventListener(service.MYSQL_RESULT, onPrimljeneResult);
	 		service.startService();	
			panel.parentApplication.glavniPanel.refreshNewMessage();
		}
		
		public function onNova(e:MouseEvent):void{
			if(!panel.parentApplication.checkExist("NOVA PORUKA")){
				var s:SuperPanel;
				panel.parentApplication.panels.push(s = tool.createPanel("NOVA PORUKA", 0, 400, 400, 50, 50, true, false, "NovaPoruka"));
				panel.parentApplication.addChild(s);
				s.backButton.addEventListener(MouseEvent.CLICK, panel.parentApplication.taskbarButtonClicked);
				s.backButton.addEventListener(MouseEvent.RIGHT_CLICK, panel.parentApplication.taskbarButtonRightClicked);
				var n:NewMessage = new NewMessage(s);	
			}
		}
	
		public function onUnCheckAll(e:MouseEvent):void{
			switch(tabNavigator.selectedChild.label){
				case "Primljene":
					listaPrimljene.selectedIndices = [];
					break;
				case "Poslate":
					listaPoslate.selectedIndices = [];
					break;
				case "U toku":
					listaUToku.selectedIndices = [];
					break;
				case "Arhiva":
					listaArhiva.selectedIndices = [];
					break;
			}
		}
		
		public function onArhive(e:MouseEvent):void{
			var i:int = 0;
			var where:String = "";
			var brisi:Boolean = false;
			switch(tabNavigator.selectedChild.label){
				case "Primljene":
					for(; i<listaPrimljene.selectedItems.length; i++){
						brisi = true;
						if(i<listaPrimljene.selectedItems.length-1) where+="id_poruka="+listaPrimljene.selectedItems[i].@id_poruka+" OR ";
							else where+="id_poruka="+listaPrimljene.selectedItems[i].@id_poruka;
					}
					break;
				case "Poslate":
					for(; i<listaPoslate.selectedItems.length; i++){
						brisi = true;
						if(i<listaPoslate.selectedItems.length-1) where+="id_poruka="+listaPoslate.selectedItems[i].@id_poruka+" OR ";
							else where+="id_poruka="+listaPoslate.selectedItems[i].@id_poruka;
					}
					break;
				case "U toku":
					for(; i<listaUToku.selectedItems.length; i++){
						brisi = true;
						if(i<listaUToku.selectedItems.length-1) where+="id_poruka="+listaUToku.selectedItems[i].@id_poruka+" OR ";
							else where+="id_poruka="+listaUToku.selectedItems[i].@id_poruka;
					}
					break;
			}
			if(brisi){
				service.sql = {type:"UPDATE", tables:"privatnaporuka p", s1:"p.procitana=2", where:where };
	 			service.addEventListener(service.MYSQL_RESULT, onDeleteResult);
		 		service.startService();
		 	}	
		}
		
		public function onDelete(e:MouseEvent):void{
			var i:int = 0;
			var where:String = "";
			var brisi:Boolean = false;
			switch(tabNavigator.selectedChild.label){
				case "Primljene":
					for(; i<listaPrimljene.selectedItems.length; i++){
						brisi = true;
						if(i<listaPrimljene.selectedItems.length-1) where+="id_poruka="+listaPrimljene.selectedItems[i].@id_poruka+" OR ";
							else where+="id_poruka="+listaPrimljene.selectedItems[i].@id_poruka;
					}
					break;
				case "Poslate":
					for(; i<listaPoslate.selectedItems.length; i++){
						brisi = true;
						if(i<listaPoslate.selectedItems.length-1) where+="id_poruka="+listaPoslate.selectedItems[i].@id_poruka+" OR ";
							else where+="id_poruka="+listaPoslate.selectedItems[i].@id_poruka;
					}
					break;
				case "U toku":
					for(; i<listaUToku.selectedItems.length; i++){
						brisi = true;
						if(i<listaUToku.selectedItems.length-1) where+="id_poruka="+listaUToku.selectedItems[i].@id_poruka+" OR ";
							else where+="id_poruka="+listaUToku.selectedItems[i].@id_poruka;
					}
					break;
				case "Arhiva":
					for(; i<listaArhiva.selectedItems.length; i++){
						brisi = true;
						if(i<listaArhiva.selectedItems.length-1) where+="id_poruka="+listaArhiva.selectedItems[i].@id_poruka+" OR ";
							else where+="id_poruka="+listaArhiva.selectedItems[i].@id_poruka;
					}
					break;
			}
			if(brisi){
				service.sql = {type:"DELETE", from:"privatnaporuka", where:where};
	 			service.addEventListener(service.MYSQL_RESULT, onDeleteResult);
		 		service.startService();
		 	}	
		}
		
		public function onDeleteResult(e:Event):void{
			var i:int = 0;
			var len:Number;
			switch(tabNavigator.selectedChild.label){
				case "Primljene":
					len = listaPrimljene.selectedIndices.length;
					for(; i<len; i++){
						listaPrimljene.dataProvider.removeItemAt(listaPrimljene.selectedIndices[i]);
					}
					break;
				case "Poslate":
					len = listaPoslate.selectedIndices.length;
					for(; i<len; i++){
						listaPoslate.dataProvider.removeItemAt(listaPoslate.selectedIndices[i]);
					}
					break;
				case "U toku":
					len = listaUToku.selectedIndices.length;
					for(; i<len; i++){
						listaUToku.dataProvider.removeItemAt(listaUToku.selectedIndices[i]);
					}
					break;
				case "Arhiva":
					len = listaArhiva.selectedIndices.length;
					for(; i<len; i++){
						listaArhiva.dataProvider.removeItemAt(listaArhiva.selectedIndices[i]);
					}
					break;
			}
		}
		
		public function onCheckAll(e:MouseEvent):void{
			var everything:Array = new Array();
			var i:int = 0;
			switch(tabNavigator.selectedChild.label){
				case "Primljene":
					for(; i < listaPrimljene.dataProvider.length; i++ ){
						everything[i] = i;
					}
					listaPrimljene.selectedIndices = everything;
					break;
				case "Poslate":
					for(; i < listaPoslate.dataProvider.length; i++ ){
						everything[i] = i;
					}
					listaPoslate.selectedIndices = everything;
					break;
				case "U toku":
					for(; i < listaUToku.dataProvider.length; i++ ){
						everything[i] = i;
					}
					listaUToku.selectedIndices = everything;
					break;
				case "Arhiva":
					for(; i < listaArhiva.dataProvider.length; i++ ){
						everything[i] = i;
					}
					listaArhiva.selectedIndices = everything;
					break;
			}
		}
				
		public function onChange(e:Event):void{
			changeContent(tabNavigator.selectedChild.label);
		}
		
		public function changeContent(s:String):void{
			switch(s){
				case "Primljene":
					izbrisi.enabled = true;
					arhiviraj.enabled = true;
					izbrisi.label = "Izbrisi";
					service.sql = {type:"SELECT", a1:"p.id_poruka", a2:"p.posiljaoc", a3:"k.username", a4:"p.procitana", a5:"p.poruka", a6:"p.attachments", a7:"p.datumSlanja", a8:"p.datumPrimanja", a9:"p.vrijemeslanja", a10:"p.vrijemeprimanja", a11:"p.naslov", a12:"p.primaoc", from:"privatnaporuka p, korisnik k", where:"k.id_username=p.posiljaoc AND procitana < 2 AND p.primaoc="+panel.parentApplication.username+" ORDER BY p.datumSlanja DESC, p.vrijemeslanja DESC" };
	 				service.addEventListener(service.MYSQL_RESULT, onPrimljeneResult);
	 				service.startService();	
					break;
				case "Poslate":
					izbrisi.enabled = false;
					izbrisi.label = "Izbrisi";
					arhiviraj.enabled = false;
					service.sql = {type:"SELECT", a1:"p.id_poruka", a2:"p.primaoc", a3:"k.username", a4:"p.procitana", a5:"p.poruka", a6:"p.attachments", a7:"p.datumSlanja", a8:"p.datumPrimanja", a9:"p.vrijemeslanja", a10:"p.vrijemeprimanja", a11:"p.naslov", a12:"p.posiljaoc", from:"privatnaporuka p, korisnik k", where:"k.id_username=p.primaoc AND p.procitana=1 AND p.posiljaoc="+panel.parentApplication.username+" ORDER BY p.datumSlanja DESC, p.vrijemeslanja DESC" };
	 				service.addEventListener(service.MYSQL_RESULT, onPoslateResult);
	 				service.startService();
					break;
				case "U toku":
					izbrisi.enabled = true;
					izbrisi.label = "Otkazi";
					arhiviraj.enabled = false;
					service.sql = {type:"SELECT", a1:"p.id_poruka", a2:"p.primaoc", a3:"k.username", a4:"p.procitana", a5:"p.poruka", a6:"p.attachments", a7:"p.datumSlanja", a8:"p.datumPrimanja", a9:"p.vrijemeslanja", a10:"p.vrijemeprimanja", a11:"p.naslov", a12:"p.posiljaoc", from:"privatnaporuka p, korisnik k", where:"k.id_username=p.primaoc AND p.procitana=0 AND p.posiljaoc="+panel.parentApplication.username+" ORDER BY p.datumSlanja DESC, p.vrijemeslanja DESC" };
	 				service.addEventListener(service.MYSQL_RESULT, onUTokuResult);
	 				service.startService();
					break;
				case "Arhiva":
					izbrisi.enabled = true;
					izbrisi.label = "Izbrisi";
					arhiviraj.enabled = false;
					service.sql = {type:"SELECT", a1:"p.id_poruka", a2:"p.primaoc", a3:"k.username", a4:"p.procitana", a5:"p.poruka", a6:"p.attachments", a7:"p.datumSlanja", a8:"p.datumPrimanja", a9:"p.vrijemeslanja", a10:"p.vrijemeprimanja", a11:"p.naslov", a12:"p.posiljaoc", from:"privatnaporuka p, korisnik k", where:"k.id_username=p.posiljaoc AND p.procitana=2 AND (p.posiljaoc="+panel.parentApplication.username+" OR p.primaoc="+panel.parentApplication.username+")"+" ORDER BY p.datumSlanja DESC, p.vrijemeslanja DESC" };
	 				service.addEventListener(service.MYSQL_RESULT, onArhivaResult);
	 				service.startService();
					break;
			}
		}
		
		public function onPrimljeneResult(e:Event):void{
			service.removeEventListener(service.MYSQL_RESULT, onPrimljeneResult);
			var xmlList:XMLList = service.xml.children();
			var xmlPom:String = "<root naziv='PrimljenePoruke'>";
			for (var i:int=0; i<xmlList.length(); i++) {
				var pom:String = "";
				if (xmlList[i].procitana==1) pom = "Da"; else pom = "Ne";
				xmlPom+="<poruka naslov='"+xmlList[i].naslov+"' id_poruka='"+xmlList[i].id_poruka+"' primaoc='"+xmlList[i].primaoc+"' posiljaoc='"+xmlList[i].posiljaoc+"' username='"+xmlList[i].username+"' procitana='"+pom+"' fullPoruka='"+xmlList[i].poruka+"' poruka='"+(tool.PlainTekst(xmlList[i].poruka)).substring(0,30)+"' attachments='"+xmlList[i].attachments+"' datumSlanja='"+xmlList[i].datumSlanja+"' datumPrimanja='"+xmlList[i].datumPrimanja+"' vrijemeslanja='"+xmlList[i].vrijemeslanja+"' vrijemeprimanja='"+xmlList[i].vrijemeprimanja+"'></poruka>";
			}
			xmlPom+="</root>";
			var xml:XML=new XML(xmlPom);
			listaPrimljene.dataProvider = xml.children();
			for(var n:Number = 0; n<listaPrimljene.columns.length; n++){		
				switch(listaPrimljene.columns[n].dataField){
					case "@username":
						listaPrimljene.columns[n].headerText = "Posiljaoc"; 
						listaPrimljene.columns[n].width = 70;						
						break;
					case "@naslov":
						listaPrimljene.columns[n].headerText = "Naslov";
						listaPrimljene.columns[n].dataTipField = "@naslov";						
						break;
					case "@procitana":
						listaPrimljene.columns[n].headerText = "Procitana";
						listaPrimljene.columns[n].width = 70;						
						break;
					default:
						listaPrimljene.columns[n].visible=false;
						break;
				}
			}
		}
		
		public function onUTokuResult(e:Event):void{
			service.removeEventListener(service.MYSQL_RESULT, onUTokuResult);
			var xmlList:XMLList = service.xml.children();
			var xmlPom:String = "<root naziv='UTokuPoruke'>";
			for (var i:int=0; i<xmlList.length(); i++) {
				var pom:String = "";
				if (xmlList[i].procitana==1) pom = "Da"; else pom = "Ne";
				xmlPom+="<poruka naslov='"+xmlList[i].naslov+"' id_poruka='"+xmlList[i].id_poruka+"' primaoc='"+xmlList[i].primaoc+"' posiljaoc='"+xmlList[i].posiljaoc+"' username='"+xmlList[i].username+"' procitana='"+pom+"' fullPoruka='"+xmlList[i].poruka+"' poruka='"+(tool.PlainTekst(xmlList[i].poruka)).substring(0,30)+"' attachments='"+xmlList[i].attachments+"' datumSlanja='"+xmlList[i].datumSlanja+"' datumPrimanja='"+xmlList[i].datumPrimanja+"' vrijemeslanja='"+xmlList[i].vrijemeslanja+"' vrijemeprimanja='"+xmlList[i].vrijemeprimanja+"'></poruka>";
			}
			xmlPom+="</root>";
			var xml:XML=new XML(xmlPom);
			listaUToku.dataProvider = xml.children(); 
			for(var n:Number = 0; n<listaUToku.columns.length; n++){		
				switch(listaUToku.columns[n].dataField){
					case "@username":
						listaUToku.columns[n].headerText = "Primaoc"; 
						listaUToku.columns[n].width = 70;					
						break;
					case "@naslov":
						listaUToku.columns[n].headerText = "Naslov";
						listaUToku.columns[n].dataTipField = "@naslov";				
						break;
					default:
						listaUToku.columns[n].visible=false;
						break;
				}
			}
		}
		
		public function onPoslateResult(e:Event):void{
			service.removeEventListener(service.MYSQL_RESULT, onPoslateResult);
			var xmlList:XMLList = service.xml.children();
			var xmlPom:String = "<root naziv='PoslatePoruke'>";
			for (var i:int=0; i<xmlList.length(); i++) {
				var pom:String = "";
				if (xmlList[i].procitana==1) pom = "Da"; else pom = "Ne";
				xmlPom+="<poruka naslov='"+xmlList[i].naslov+"' id_poruka='"+xmlList[i].id_poruka+"' posiljaoc='"+xmlList[i].posiljaoc+"' primaoc='"+xmlList[i].primaoc+"' username='"+xmlList[i].username+"' procitana='"+pom+"' fullPoruka='"+xmlList[i].poruka+"' poruka='"+(tool.PlainTekst(xmlList[i].poruka)).substring(0,30)+"' attachments='"+xmlList[i].attachments+"' datumSlanja='"+xmlList[i].datumSlanja+"' datumPrimanja='"+xmlList[i].datumPrimanja+"' vrijemeslanja='"+xmlList[i].vrijemeslanja+"' vrijemeprimanja='"+xmlList[i].vrijemeprimanja+"'></poruka>";
			}
			xmlPom+="</root>";
			var xml:XML=new XML(xmlPom);
			listaPoslate.dataProvider = xml.children(); 
			for(var n:Number = 0; n<listaPoslate.columns.length; n++){		
				switch(listaPoslate.columns[n].dataField){
					case "@username":
						listaPoslate.columns[n].headerText = "Primaoc"; 
						listaPoslate.columns[n].width = 70;						
						break;
					case "@naslov":
						listaPoslate.columns[n].headerText = "Naslov";
						listaPoslate.columns[n].dataTipField = "@naslov";
						break;
					case "@procitana":
						listaPoslate.columns[n].headerText = "Procitana";
						listaPoslate.columns[n].width = 70;						
						break;
					default:
						listaPoslate.columns[n].visible=false;
						break;
				}
			}
		}
		
		public function onArhivaResult(e:Event):void{
			service.removeEventListener(service.MYSQL_RESULT, onArhivaResult);
			var xmlList:XMLList = service.xml.children();
			var xmlPom:String = "<root naziv='ArhivaPoruke'>";
			for (var i:int=0; i<xmlList.length(); i++) {
				xmlPom+="<poruka naslov='"+xmlList[i].naslov+"' id_poruka='"+xmlList[i].id_poruka+"' posiljaoc='"+xmlList[i].posiljaoc+"' primaoc='"+xmlList[i].primaoc+"' username='"+xmlList[i].username+"' fullPoruka='"+xmlList[i].poruka+"' poruka='"+(tool.PlainTekst(xmlList[i].poruka)).substring(0,30)+"' attachments='"+xmlList[i].attachments+"' datumSlanja='"+xmlList[i].datumSlanja+"' datumPrimanja='"+xmlList[i].datumPrimanja+"' vrijemeslanja='"+xmlList[i].vrijemeslanja+"' vrijemeprimanja='"+xmlList[i].vrijemeprimanja+"'></poruka>";
			}
			xmlPom+="</root>";
			var xml:XML=new XML(xmlPom);
			listaArhiva.dataProvider = xml.children(); 
			for(var n:Number = 0; n<listaArhiva.columns.length; n++){		
				switch(listaArhiva.columns[n].dataField){
					case "@username":
						listaArhiva.columns[n].headerText = "Autor"; 
						listaArhiva.columns[n].width = 70;						
						break;
					case "@naslov":
						listaArhiva.columns[n].headerText = "Naslov";
						listaArhiva.columns[n].dataTipField = "@naslov";						
						break;
					default:
						listaArhiva.columns[n].visible=false;
						break;
				}
			}
		}

		public function onResize(e:Event):void{
			tabNavigator.width = panel.width-35;
			tabNavigator.height = panel.height-85;
			listaArhiva.width = tabNavigator.width-2;
			listaArhiva.height = tabNavigator.height-32;
			listaPoslate.width = tabNavigator.width-2;
			listaPoslate.height = tabNavigator.height-32;
			listaPrimljene.width = tabNavigator.width-2;
			listaPrimljene.height = tabNavigator.height-32;
			listaUToku.width = tabNavigator.width-2;
			listaUToku.height = tabNavigator.height-32;
			izbrisi.x = panel.width-88;
			izbrisi.y = panel.height-45;
			arhiviraj.x = panel.width-168;
			arhiviraj.y = panel.height-45;
			nova.x = panel.width-236;
			nova.y = panel.height-45;
			checkAll.y = panel.height-45;
			unCheckAll.y = panel.height-45;
		}
	}
}